package com.kmgames.ballsengine.physics;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;

public class StaticObjectFactory extends ObjectFactory {
	public StaticObjectFactory(World world) {
		super(world);
	}

	public void square(float height, Vector2 center) {
		float half = height / 2;
		Vector2[] vertices = new Vector2[4];

		vertices[0] = center.cpy().add(-half, -half);
		vertices[1] = center.cpy().add(half, -half);
		vertices[2] = center.cpy().add(half, half);
		vertices[3] = center.cpy().add(-half, half);

		createPolygon(vertices);
	}

	private void createPolygon(Vector2[] vertices) {
		for (int i = 0; i < vertices.length; i++) {
			int begin = i;
			int end = (i + 1) % vertices.length;
			createEdge(vertices[begin], vertices[end]);
		}
	}

	private void createEdge(Vector2 begin, Vector2 end) {
		PolygonShape shape = new PolygonShape();
		shape.setAsEdge(begin, end);

		createFixture(BodyType.StaticBody, shape);
	}
}
